import {
	useUserStore
} from '@/stores/user.js'
const userStore = useUserStore()
uni.addInterceptor('request', {
	invoke(args) {
		// request 触发前拼接 url
		uni.showToast({
			title: "加载中(￣3￣)～",
			icon: "loading"
		})
		args.url = 'https://api-hmugo-web.itheima.net' + args.url
		if (args.url.indexOf('/my/') !== -1) {
			args = {
				...args,
				header: {
					"content-type": "application/json",
					Authorization: userStore.token
				}
			}
			console.log(args);
		}
	},
	success(args) {

	},
	fail(err) {
		console.log('interceptor-fail', err)
	},
	complete(res) {
		uni.hideToast()
	}
})
// 封装弹框方法：
uni.$showMsg = (title = "请求失败＞﹏＜", duration = 1111) => {
	uni.showToast({
		title,
		duration,
		icon: "none"
	})
}
// uni.addInterceptor({
// 	returnValue(args) {
// 		// 只返回 data 字段
// 		return args.data
// 	}
// })
export default uni